using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for SinhVienDAO
/// </summary>
public class SinhVienDAO:DataProvider
{
	public SinhVienDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public ArrayList LayMang_SinhVien()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_SinhVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                SinhVienDTO obj = new SinhVienDTO();
                obj.MaSinhVien = dr.GetString(0);
                obj.HoTenSV = dr.GetString(1);
                obj.Email = dr.GetString(2);
                obj.DTB = dr.GetFloat(3);
                arr.Add(obj);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        return arr;

    }
    public void insert(SinhVienDTO obj)
    {
        connect();

        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_SinhVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@HoTenSV", SqlDbType.NVarChar);
            cmd.Parameters["@HoTenSV"].Value = obj.HoTenSV.ToString();
            cmd.Parameters["@HoTenSV"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@Email", SqlDbType.NVarChar);
            cmd.Parameters["@Email"].Value = obj.Email.ToString();
            cmd.Parameters["@Email"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@DTB", SqlDbType.Float);
            cmd.Parameters["@DTB"].Value = obj.DTB;
            cmd.Parameters["@DTB"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void delete(string MaSinhVien)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Delete_SinhVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaSinhVien", SqlDbType.VarChar);
            cmd.Parameters["@MaSinhVien"].Value = MaSinhVien;
            cmd.Parameters["@MaSinhVien"].Direction = ParameterDirection.Input;
            cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void update(SinhVienDTO obj)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_SinhVien", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaSinhVien", SqlDbType.VarChar);
            cmd.Parameters["@MaSinhVien"].Value = obj.MaSinhVien.ToString();
            cmd.Parameters["@MaSinhVien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@HoTenSV", SqlDbType.NVarChar);
            cmd.Parameters["@HoTenSV"].Value = obj.HoTenSV.ToString();
            cmd.Parameters["@HoTenSV"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@Email", SqlDbType.NVarChar);
            cmd.Parameters["@Email"].Value = obj.Email.ToString();
            cmd.Parameters["@Email"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@DTB", SqlDbType.Float);
            cmd.Parameters["@DTB"].Value = obj.DTB;
            cmd.Parameters["@DTB"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();

        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
}
